#include <iostream>
#include <memory>
#include <vector>
class Subject;
// 观察者类
class Observer {
 public:
  Observer(Subject* subject);
  virtual void Update() = 0;

 protected:
  Subject* subject_;
};
class Observer1 : public Observer {
 public:
  Observer1(Subject* subject);
  void Update() override;

 private:
};

// 对象类
// 基类，通过继承防止代码膨胀问题
class Subject {
 public:
  void Attach(Observer* observer);
  void Detach(Observer* observer);

  void Notify();

 private:
  int val_ = 0;
  std::vector<Observer*> observers_;
};
// 具体对象类
class ConcreteSubjectInt : public Subject {
 public:
  int GetVal() const;
  void SetVal(const int val);

 private:
  int val_ = 0;
};
// TODO:如果使用智能指针怎么实现